function [x,POPULATION] = objFunGa(param)
% Objective Function for multiobjective optimization with
% gamultiobj
% Lucas Beck, 10. April 2008

% define new demand with function demandGen

% Modify optimization parameters
options= gaoptimset;
options = gaoptimset(options,'PopulationSize',6);
options = gaoptimset(options,'Generations',10);
options = gaoptimset(options,'MutationFcn',@mutationadaptfeasible);
options = gaoptimset(options,'StallTimeLimit',200);
options = gaoptimset(options,'PlotFcns',{@gaplotpareto});
options = gaoptimset(options,'TolFun',1e-6);
%options = gaoptimset(options,'CreationFcn',@gacreationlinearfeasible);
lb=[0 0];
ub=[30 30];
[x,FVAL,EXITFLAG,OUTPUT,POPULATION] = gamultiobj(@gaopt,2,[],[],[],[],lb,ub,options )

function F = gaopt(x)

     % Assign the values of x() to the variables used in the
     % Simulation model. New demand will be generated
      
     param.d(:,1) = demandGen(x(1),param.sigmaD,param.tEnd, ...
                        param.dGrowth)';
     param.d(:,2) = demandGen(x(2),param.sigmaD,param.tEnd, ...
                        param.dGrowth)';
     % Run the simulation
     tt = resLearnAg(param,param.d,param.q,'disc','undirE');
          
     % Now the objective functions
     F(1)=-sum(abs(tt.r(:,1)));
     F(2)=-sum(abs(tt.r(:,2)));
     
end

end